/**************************************************************************
* FXTranslate
* Copyright (C) 2009 thierry lorthiois (lorthiois@bbsoft.fr)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
**************************************************************************/
/**************************************************************************
* FXTranslate manage translation
* - build translation file from source
* - load translation in FXStringDict
* 
**************************************************************************/


#ifndef FXTRANSLATE_H
#define FXTRANSLATE_H

#include "fx.h"

#ifndef FXTRANSLATOR_H
#include "FXTranslator.h"
#endif

namespace FX {

#define MAXBUFFER 2000

class FXAPI FXTranslate : public FXTranslator {
	FXDECLARE(FXTranslate)
protected:
	FXTranslate() {}
public:
	/// Construct translator
	FXTranslate(FXApp* a);

	/// Destructor
	virtual ~FXTranslate();

	virtual const FXchar *tr(const FXchar *context, const FXchar *message, const FXchar *hint=NULL) const;

	// load PO file in FXStringDict
	bool load(const FXString &filename);

	// build PO file from source
	// browse directory, search 'pattern' files, and store tr() message into filename
	bool buildTranslation(const FXString &dir, const FXString &pattern, const FXString &filename);

	// TODO
	// simplified migration between version
	void mergeMessage(const FXString &fileSrc, const FXString &fileDest);

private:
	bool browseDir(const FXString &dir, const FXString &pattern, FXFile &file, FXchar *buffer);
	bool storeMessage(FXFile &file, FXchar *buffer, const FXString &filename);

	// following functions are shared with FXSettings
	static FXchar* dequote(FXchar* text);
	static bool readString(FXFile& file,FXchar *buffer,FXint& bol,FXint& eol,FXint& end);

private:
	FXStringDict map;
};

}

#endif

